package cn.com.flever.handler;

import com.alibaba.fastjson.JSONObject;
import io.netty.channel.Channel;
import java.lang.reflect.Method;
import java.util.HashMap;

public class PCHandler extends AbstractHandler{

    public static HashMap<String, Channel> clientMap=new HashMap<>();

    @Override
    public JSONObject clientUp(JSONObject req, Channel channel) {
        //获取PC端的token
        String token=req.getString("token");
        String uuid=req.getString("uuid");
        clientMap.put(token,channel);
        JSONObject res=new JSONObject();
        res.put("uuid", uuid);
        res.put("code","200");
        res.put("message","PC端上线成功");
        return res;
    }

    @Override
    public JSONObject dispacher(JSONObject req, Channel channel) {
        try {
            String methodName=req.getString("method");
            Method method=this.getClass().getMethod(methodName,JSONObject.class,Channel.class);
            JSONObject res= (JSONObject) method.invoke(this,req,channel);
            return res;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
